<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Customer</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<div class="layuimini-container" id="app">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>返利套现监控</legend>
            <div style="margin: 10px 10px 10px 10px">
                <div class="layui-form layui-form-pane" action="javascript:;" lay-filter="table-search">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">选择区服:</label>
                            <div class="layui-input-inline">
                                <select name="gameArea" class="layui-select">
                                    <option v-for="(item,index) in services" :value="item.server_id" :selected="index==0">{{item.name}}</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">角色名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="roleName" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">角色ID</label>
                            <div class="layui-input-inline">
                                <input type="text" name="roleId" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">物品名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="itemName" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">物品ID</label>
                            <div class="layui-input-inline">
                                <input type="text" name="itemId" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">操作类型</label>
                            <div class="layui-input-inline">
                                <div id="operTypes"></div>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">记录时间</label>
                            <div class="layui-input-inline">
                                <input type="text" name="createDateBegin" id="createTime0"
                                       placeholder="开始时间" autocomplete="off" class="layui-input" />
                                <input type="text" name="createDateEnd" id="createTime1"
                                       placeholder="截止时间" autocomplete="off" class="layui-input" />
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="button" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i>搜 索</button>
                        </div>
                    </div>
                </div>
            </div>
        </fieldset>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

    </div>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="export" auth="equipment:export">导出</button>
    </div>
</script>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="/js/common.js?v=5" charset="utf-8"></script>
<script src="/xm-select-v1.2.4/xm-select.js"></script>
<script>
    var operTypes = getEnum('operType')
    var equipments = getEnum('equip')
    function getEquipName(itemId) {
        for(var k in equipments){
            if (equipments[k].id === itemId){
                return equipments[k].name;
            }
        }
        return itemId;
    }

    let services = JSON.parse(localStorage.getItem('services'));
    services.unshift({ server_id: 0, name: '全部' });
    new Vue({
        el: "#app",
        data: {
            services: services,
        },
        mounted: function () {
            layui.use(['form', 'table','laydate'], function () {
                var $ = layui.jquery,
                    form = layui.form,
                    table = layui.table,
                    laydate=layui.laydate;

                laydate.render({
                    elem: '#createTime0',
                    value: getYmd(0)
                });
                laydate.render({
                    elem: '#createTime1',
                    value: getYmd(1),
                })
                var data = [];
                for(var k in operTypes){
                    var v = operTypes[k];
                    data.push({
                        name:v.name,
                        value:v.id,
                    })
                }

                xmSelect.render({
                    el: '#operTypes',
                    name:"opTypes",
                    language: 'zn',
                    data: data
                })
                function getContainerName(type){
                    if (type===0) return '无'
                    if (type===1) return '背包'
                    if (type===2) return '装备栏'
                    if (type===3) return '仓库'
                    if (type===4) return '精灵背包'
                    if (type===5) return '摊位'
                }
                table.render({
                    elem: '#currentTableId',
                    where:form.val('table-search'),
                    url: '/admin/equipment/monitorpaginate',
                    defaultToolbar: ['filter', 'print' ],
                    toolbar: '#toolbarDemo',
                    width:1850,
                    cols: [[
                        {type: "checkbox", width: 50},
                        {field: 'nowdata', title:'记录时间',width:180 ,templet(d){
                                var dateTime = new Date(d.nowdata);
                                console.log('日期',dateTime)
                                var dateOnly = dateTime.toLocaleDateString();
                            return dateOnly;
                            }},
                        {field: 'equipName', title:'物品名称'},
                        {field: 'gameArea', title:'服务器ID'},
                        {field: 'roleId', title:'角色ID'},
                        {field: 'name', title:'角色名'},
                        { field:"opTypeName",title:"操作类型",
                            templet:function (d) {
                                if (d.opTypeName) {
                                    return d.opTypeName;
                                } else {
                                    return d.opType;
                                }
                            }
                        },
                        {field: 'points', title:'当前计数'},
                        {field: 'itemId', title:'物品ID'},

                    ]],

                    done:function(res,curr){
                        if(res.heap>72){
                            // 2秒后关闭消息提示
                            setTimeout(function() {
                                alert('数据运算压力较大,请稍后重试！');
                            }, 5000); // 1000毫秒等于1秒

                        }
                    },
                    limits: [10, 15, 20, 25, 50, 100],
                    limit: 15,
                    page: true,
                    skin: 'line'
                });
                form.on('submit(data-search-btn)', function () {
                    // 执行搜索重载
                    table.reload('currentTableId', {
                        where: form.val('table-search'),
                        page: {
                            curr: 1
                        },
                        done: function (res) {
                            if (res.count >= 2999999) {
                                alert('请缩小时间范围，进行精确查询！');
                            }
                        }
                    });

                    return false;
                });
                table.on('toolbar(currentTableFilter)', function (obj) {
                    if(obj.event === 'export'){ //导出
                        var searchData = form.val('table-search');
                        searchData.page = 1;
                        searchData.limit = 9999999;
                        var layerIndex = layer.msg("请求中请耐心等待...",{icon:16,time:999999999});
                        $.get('/admin/equipment/monitorexport',searchData,function(res){
                            layer.close(layerIndex)
                            browserDownload("/" + res.data);
                        });
                    }
                });
            });
        }
    })
</script>
</body>
</html>